package com.example.timetracker;

import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TimeTrackerAdapter extends BaseAdapter {
	private ArrayList<TimeRecord> listTimes = new ArrayList<TimeRecord>();
	
	public TimeTrackerAdapter(){
		super();
	}
	
	public void setListTimes(ArrayList<TimeRecord> listTimes) {
		this.listTimes = listTimes;
	}

	@Override
	public int getCount() {
		return listTimes.size();
	}
	
	public void addTimeRecord(TimeRecord timeRecord){
		listTimes.add(timeRecord);
	}

	@Override
	public TimeRecord getItem(int position) {
		return listTimes.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null){
			LayoutInflater inflater = LayoutInflater.from(parent.getContext());
			convertView = inflater.inflate(R.layout.time_list_item, parent, false);
		}
		
		TimeRecord time = listTimes.get(position);
		
		TextView timeTextView = (TextView) convertView.findViewById(R.id.timeView);
		timeTextView.setText(time.getTime());
		
		TextView notesTextView = (TextView) convertView.findViewById(R.id.notesView);
		notesTextView.setText(time.getNotes());
		
		return convertView;
		
	}


}
